package com.stone.business.plan.action;

/**
 * <pre>
 * ----计划列表 Action---
 * </pre>
 */

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import com.stone.business.plan.pojo.TPlan;
import com.stone.business.plan.service.PlanService;
import com.stone.para.IConstant;
import com.stone.sys.pojo.TBdz;
import com.stone.sys.pojo.TDictionary;
import com.stone.sys.pojo.TOrgan;
import com.stone.utils.StringUtils;

import frm.ssh.action.BaseListAction;

public class MonthplanAfterDayListAction extends BaseListAction {

	private PlanService planService;
	
	public PlanService getPlanService() {
		return planService;
	}

	public void setPlanService(PlanService planService) {
		this.planService = planService;
		this.service=planService;
	}
	
	/** * 构造方法. */
    public MonthplanAfterDayListAction() {
        this.entityClass = TPlan.class;
    }
	private String hiddenids;
	private List<TBdz> bdzList;
	private List<TDictionary> dydjList;
	private List<TDictionary> sblxList;
    
	
	/**
	 * 设置查询条件
	 */
	public HashMap<String, Object> setSearchCondition() {
	
		HashMap<String, Object> m = new HashMap<String, Object>();
		List<Object> valsList = new ArrayList<Object>();
		String organCode = String.valueOf(super.getSession().getAttribute(IConstant.SESSION_TORGAN_CODE));
		m.put("cols", "plan");
		 
		
		
		
		String conditions = "1=1";
		
			TOrgan o  = (TOrgan)super.getSession().getAttribute(IConstant.SESSION_TORGAN);
			if (o.getOrganCode().toString().length() > 6 && !"1".equals(super.getSession().getAttribute("SESSION_ISADMIN"))) {
				conditions += " and ouid = '" + o.getOrganCode() + "'";
			}
			 if ("3".equals(super.getSearchBean().getCon20())) {
			 
			 	conditions += " AND status = 9";
				conditions += " and startdate - trunc(sysdate) = 2";

			} else if ("4".equals(super.getSearchBean().getCon20())) {
				
				conditions += " AND status = 9";
				conditions += " and startdate - trunc(sysdate) = 1";

			} else if ("5".equals(super.getSearchBean().getCon20())) {
				
				conditions += " AND status = 9";
				conditions += " and startdate - trunc(sysdate) = 0";

			}

		 

		//----------------------查询条件---------------------
		if (!StringUtils.isNullOrBlankFull(super.getSearchBean().getCon1())){
			conditions += " AND plan.ouid like ? ";
			valsList.add(organCode+ "%");
		}
		
		// 开始时间
		if (!StringUtils.isNullOrBlankFull(super.getSearchBean().getCon2())){
			conditions += " AND plan.startdate like >= ?";
			valsList.add(super.getSearchBean().getCon2());
		}
		
		if (!StringUtils.isNullOrBlankFull(super.getSearchBean().getCon3())){
			conditions += " AND plan.startdate like <= ?";
			valsList.add(super.getSearchBean().getCon3());
		}
		
		// 班组
		if (!StringUtils.isNullOrBlankFull(super.getSearchBean().getCon5())){
			conditions += " AND plan.teamnames like ? ";
			valsList.add("%" + super.getSearchBean().getCon5().replaceAll(",", "%") + "%");
		}
	
		m.put("conditions",conditions);
		m.put("clause"," order by plan.id desc");
		m.put("alias", "plan");
		m.put("vals", valsList.toArray());
		
		setDictionary();
		
		return m;
		
	}

	// 获得字典项目
	private void setDictionary() {
		
		// 变电站
		this.bdzList = planService.findListByHql(" from TBdz order by sortid");
		// 电压等级
		this.dydjList = planService.findListByHql(" from TDictionary where itemType = 'DYDJ' order by sortid");
		// 电压等级
		this.sblxList = planService.findListByHql(" from TDictionary where itemType = 'SBLX' order by sortid");
	}

	public List<TBdz> getBdzList() {
		return bdzList;
	}

	public List<TDictionary> getDydjList() {
		return dydjList;
	}

	public List<TDictionary> getSblxList() {
		return sblxList;
	}
	
	public String getHiddenids() {
		return hiddenids;
	}

	public void setHiddenids(String hiddenids) {
		this.hiddenids = hiddenids;
	}
	
}
